package com.yxx.controller.admin;

import com.yxx.medicinecommon.result.PageResult;
import com.yxx.medicinecommon.result.ResponseResult;
import com.yxx.medicinepojo.dto.SetMedicinePageQueryDTO;
import com.yxx.medicinepojo.dto.SetmedicineDTO;
import com.yxx.medicinepojo.vo.SetmedicineVO;
import com.yxx.service.SetMedicineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 组合药管理
 * @author yuxiangxun
 * @date 2024/9/13
 * @apiNote
 */
@Slf4j
@RestController
@Api(tags = "组合药管理相关接口")
@RequestMapping("/admin/setmedicine")
public class SetMedicineController {

    @Autowired
    private SetMedicineService setMedicineService;

    /**
     * 组合药分页查询
     * @param setMedicinePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("组合药分页查询")
    public ResponseResult<PageResult> page(SetMedicinePageQueryDTO setMedicinePageQueryDTO){
        PageResult pageResult = setMedicineService.pageQuery(setMedicinePageQueryDTO);
        return ResponseResult.success(pageResult);
    }

    /**
     * 新增组合药
     * @param setmedicineDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增组合药")
    public ResponseResult saveSetMedicine(@RequestBody SetmedicineDTO setmedicineDTO){
        setMedicineService.saveSetdicineWithMedicine(setmedicineDTO);
        return ResponseResult.success();
    }

    /**
     * 回显数据，根据组合药id查询组合药信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("回显数据，根据组合药id查询组合药")
    public ResponseResult<SetmedicineVO> Setmedicine_Select_update_getById(@PathVariable Long id){
        SetmedicineVO setmedicineVO = setMedicineService.getById_Setmedicine(id);
        return ResponseResult.success(setmedicineVO);
    }

    /**
     * 修改组合药
     * @param setmedicineDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改组合药")
    public ResponseResult update_SetMedicine(@RequestBody SetmedicineDTO setmedicineDTO){
        setMedicineService.update_SetMedicine_Medicine(setmedicineDTO);
        return ResponseResult.success();
    }

    /**
     * 组合药上架下架
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("组合药上架下架")
    public ResponseResult SetMedicine_Start_Disable(
            @ApiParam(value = "状态 0:下架，1:上架",required = true) @PathVariable("status") Integer status,
            @ApiParam(value = "组合药id", required = true) Long id){
        setMedicineService.SetMedicine_Start_Disable(status,id);
        return ResponseResult.success();
    }

    /**
     * 批量删除组合药
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("批量删除组合药")
    public ResponseResult deleteSetMedicine(@RequestParam List<Long> ids){
        setMedicineService.deleteSetMedicineBatch(ids);
        return ResponseResult.success();
    }

}
